W10. Nondeterminism and Computability
1. Theory
1.1 Determinism vs. Nondeterminism
1.1.1 Deterministic Computation
A Deterministic Finite State Automaton (DFSA) is the classical model in which every state-input pair maps to exactly one next state. Formally, a DFSA is a 5-tuple
is a finite set of states; is a finite input alphabet; is a total transition function — for every state and every input symbol, the next state is uniquely determined; is the initial state; is the set of accepting states.
The transition function
1.1.2 Nondeterministic Computation
Nondeterminism extends the deterministic model by allowing, from a single state on a single input symbol, zero, one, or more possible transitions. Rather than following one fixed path, a nondeterministic machine conceptually explores all branches simultaneously.
A Nondeterministic Finite State Automaton (NFSA) (also written NDFSA) is a tuple
where
The key intuition is that nondeterminism models parallel exploration: the machine simultaneously pursues every possible transition. In terms of implementation, think of it as forking a thread for each possible next state.
1.1.3 The Extended Transition Function
For both deterministic and nondeterministic automata, we extend the transition function from single symbols to whole strings.
For an NFSA
- For every
: — reading the empty string leaves the machine in the same state. - For every
, , and : That is, after reading the machine is in some set of states; reading one more symbol applies to each of those states and takes the union of all resulting sets.
Example. Suppose
1.1.4 Acceptance Condition for an NFSA
A string
This is called existential nondeterminism: it is sufficient that one computation path leads to an accepting state. If even one branch succeeds, the string is accepted.
There is also a universal interpretation (used in different contexts):
1.1.5 NFSA with -Transitions
An
An
The extended transition function for
1.2 Equivalence of DFSA and NFSA
One of the fundamental results of automata theory is that DFSA and NFSA recognize exactly the same class of languages — the regular languages. Nondeterminism does not add expressive power for finite automata; it only offers a convenience for design.
1.2.1 Subset Construction Algorithm
Given an NFSA
— each state of the DFSA corresponds to a subset of NFSA states (hence the name subset construction or powerset construction). — the DFSA starts in the singleton set containing the NFSA’s initial state. — a DFSA state is accepting if it contains at least one NFSA accepting state. for each and .
Stepwise procedure:
- Build the NFSA transition table.
- Create a DFSA table; mark the start state as
. - For each DFSA state (which is a set of NFSA states) and each input symbol, compute
by unioning the NFSA transitions from all states in the set. - Each new set computed in step 3 that has not been seen before becomes a new DFSA state; repeat step 3 for it.
- Terminate when no new DFSA states are produced.
- Mark all DFSA states that contain an NFSA accepting state as accepting.
Worst-case cost: If the NFSA has
1.2.2 Why Use NFSA if They Add No Power?
Even though NFSAs recognize no more languages than DFSAs, they are valuable for two reasons:
- Ease of design. An NFSA for a pattern is often far simpler to construct. For example, the NFSA recognizing strings containing the substring
is a linear chain of 7 states, while the equivalent DFSA requires careful handling of every possible partial match failure. - Exponential state compression. An NFSA with
states can represent a language whose minimal DFSA requires states. NFSAs are therefore an important intermediate representation in compiler construction (lexical analysis) and pattern matching.
1.3 Regular Expressions
Regular expressions (RegExps) were introduced by Stephen Kleene as a compact algebraic notation for describing regular languages. They are used ubiquitously in text search, compilers, and formal verification.
1.3.1 Syntax and Inductive Definition
A regular expression over an alphabet
Basis:
is a RegExp, denoting the empty language . is a RegExp, denoting — the language containing only the empty string.- Each symbol
is a RegExp, denoting .
Induction. If
is a RegExp: union, . is a RegExp (dot often omitted): concatenation, . is a RegExp: Kleene star, .
The additional notation
1.3.2 Operator Precedence
When parentheses are omitted, operations are evaluated in this order (highest to lowest priority):
(Kleene star) (concatenation) (union)
So
1.3.3 Examples
any string over = strings over that start or end with 0.
1.4 Thompson’s Construction: RegExp to NFSA
Thompson’s Construction is an algorithm that systematically converts any regular expression into an
1.4.1 Base Cases
For a single symbol
1.4.2 Concatenation:
Connect the accepting state of
1.4.3 Union:
Create a new start state
1.4.4 Kleene Star:
Create a new start state
(enter the inner machine), (bypass, for zero repetitions), (loop back for additional repetitions), (exit).
1.4.5 -Elimination (Simplification)
After Thompson’s Construction, the resulting NFSA often contains redundant
1.5 Historical Background of Turing Machines
The Turing Machine emerged from a profound philosophical and mathematical crisis in the early 20th century.
1.5.1 Principia Mathematica and Logicism
In 1910–1913, Bertrand Russell and Alfred North Whitehead published the Principia Mathematica — a monumental 2,000-page attempt to axiomatize all of mathematics from pure logical principles. The project embodied logicism: the philosophical thesis that mathematical truths are reducible to, and derivable from, pure logic. The authors claimed their system was both complete (every mathematical truth could be derived) and consistent (no falsehood could be derived).
1.5.2 Gödel’s Incompleteness Theorems (1931)
Kurt Gödel shattered the logicist program. In 1931, he proved his Incompleteness Theorems: in any sufficiently powerful logical system, there exist statements that are true but cannot be proven within the system. No consistent formal system powerful enough to describe arithmetic can prove all arithmetic truths. Gödel’s result showed that the goals of Principia Mathematica were unachievable: completeness and consistency cannot coexist for sufficiently rich systems.
1.5.3 Hilbert’s Entscheidungsproblem (1928)
David Hilbert, also committed to the formalization of mathematics, posed the Entscheidungsproblem (German: decision problem) in 1928: is there an algorithm that, given any mathematical proposition and a set of axioms, decides whether that proposition is provable from the axioms? Hilbert called it “the fundamental problem of mathematical logic” — an affirmative answer would reduce all of mathematics to mechanical calculation.
1.5.4 Church and Turing’s Negative Answer (1936)
In 1936, independently, Alonzo Church (using
Turing’s key insight was to model the mechanical process of following rules: a human mathematician, he argued, is essentially a machine that reads symbols, maintains a finite amount of state, and applies rules. By formalizing this as a mathematical object, he could then prove precise limitations.
1.5.5 The Church–Turing Thesis
The Church–Turing thesis (not a theorem, but a widely accepted conjecture) states that:
Any computation that can be carried out by any realizable physical process can be computed by a Turing Machine (equivalently, expressed in
-calculus).
This thesis equates the informal notion of “effectively computable” with the formal notion of “Turing-computable.” It is the foundation of modern computability theory.
1.5.6 Turing’s Philosophical Contribution
Before Turing, the prevailing view was idealist: through pure mathematical reasoning, the human mind accesses a Platonic realm of eternal truths. After Turing, the view became materialist: the Turing Machine is a model of the human mathematician. The limits of the machine are the limits of mathematical reasoning. Mathematics is grounded in what the physical world allows — not in a transcendent Platonic domain. Turing’s work marked a fundamental epistemological break in the philosophy of mathematics.
1.6 Turing Machines: Architecture and Formal Definition
1.6.1 Components of a Turing Machine
A Turing Machine (TM) consists of:
- An input tape: a read-only, one-directional sequence of cells containing the input string, followed by blank cells.
- A control device (finite state control): maintains the current state
and specifies transitions. - Memory tapes (
tapes): read/write tapes with a movable head; each cell holds a symbol from the memory alphabet . The memory tapes are non-destructive — writing to a cell does not erase other cells. - An output tape: a write-only tape.
The key distinction from a PDA is memory persistence: the TM can re-read previously written memory symbols, whereas a PDA’s stack destroys symbols on pop.
1.6.2 Formal Definition
A TM with
: finite set of states; : input alphabet (symbols on the input tape); : memory alphabet (symbols writable on memory tapes; and may differ); : transition function; : initial state; : initial memory symbol (initially fills each memory tape — analogous to the bottom-of-stack marker); : set of accepting states.
1.6.3 The Transition Function
Reading this left to right:
- Domain: The machine is in a non-accepting state, has read one symbol from the input tape, and one symbol from each of the
memory tapes. - Codomain: The machine transitions to a new state, writes a new symbol on each memory tape, and moves each of the
heads (one input head plus memory heads).
The three head movement directions are:
— move right — move left — stay in place
A transition is depicted graphically as an edge
1.7 Turing Machine Examples
1.7.1 Recognizing
The language
- Read each
from the input and write an on the memory tape (store markers). - When all
’s are read, move left on the memory tape and start reading ’s. For each , consume one from memory (move left). - When we’ve consumed all
’s (reached ) and the input shows a , move right on the memory tape and start reading ’s, consuming one per . - Accept when both the input and the memory tape are fully consumed simultaneously.
This works because the memory tape is persistent — the
1.7.2 Recognizing
For
- For each
read, write two ’s on the memory tape (so the tape holds ’s total). - Read
’s from the input while consuming ’s leftward on the memory tape (one per ), verifying ’s. - Read the final
’s while consuming ’s rightward on the memory tape (consuming the tape a second time for the trailing ’s). - Accept when both tapes are exhausted simultaneously.
1.7.3 Recognizing
The TM stores
1.8 Variants of Turing Machines and Their Equivalence
1.8.1 Single-Tape TM
A single-tape TM uses one tape for input, memory, and output. The tape is unbounded in both directions. Despite this apparent restriction, the single-tape TM is equivalent in expressive power to the multi-tape TM: any multi-tape TM can be simulated by a single-tape TM. The simulation encodes all tapes onto one tape using separator markers, and tracks all head positions. This may incur a polynomial or quadratic slowdown but does not change what can be computed.
1.8.2 Multidimensional-Tape TM
A 2D-tape TM (or
1.8.3 Universal Equivalence
All reasonable TM variants (single tape, multi-tape, multi-dimensional, non-deterministic TM, etc.) recognize exactly the same class of languages — the recursively enumerable languages. This robustness is evidence that the TM captures the right notion of computation, as stated by the Church–Turing thesis.
1.9 Closure Properties of Turing Machines
The class of recursively enumerable languages (languages recognized by TMs) is closed under:
- Union: Given TMs
and , build a TM that simulates both in parallel; accept if either accepts. - Intersection: Simulate both in series; accept only if both accept.
- Concatenation: Nondeterministically guess a split point; run
on the first part and on the second. - Kleene star: Nondeterministically guess decompositions; verify each part.
The intuition for union and intersection is that a TM can easily simulate two other TMs in series or in parallel.
Not closed under complement. TMs are not closed under complement. The reason is that a TM that does not accept a string may either reject it (halt in a non-accepting state) or loop forever. Swapping accepting and non-accepting halting states works for loop-free TMs, but cannot handle non-terminating computations.
Loop-free TMs are closed under complement: For TMs that are guaranteed to halt on all inputs (called recursive or decidable), swapping accepting and rejecting states produces a TM for the complemented language. This is the class of recursive languages (a strict subset of the recursively enumerable languages).
1.10 The Language Hierarchy
The following diagram summarizes the Chomsky hierarchy as discussed throughout the course:
Key observations:
- Regular languages (recognized by FSA): only fixed, finite memory — no generic counting to
. - Deterministic CFL (recognized by DPDA): stack memory, but restricted to deterministic transitions.
- Context-free languages (recognized by nondeterministic PDA): stack is destructive; cannot count multiple independent quantities simultaneously.
- Recursive (Decidable) languages: TMs that always halt; closed under complement.
- Recursively enumerable languages: TMs that may loop; not closed under complement.
- Non-Turing-recognizable: languages that no TM can recognize.
The difference between recursive and recursively enumerable languages can be illustrated with C programs:
- The set of C programs that never run into an infinite loop (on any input) is recursive.
- The set of C programs that contain an infinite loop (on at least one input) is recursively enumerable but not recursive — this is related to the Halting Problem.
1.11 The Memory Model Perspective
The choice of memory model determines the expressive power of a computational model:
- FSA — fixed, finite memory: the current state is the only memory. You can only “count” up to the finite number of states. No generic variable
. - PDA — extensible but destructive memory (stack): can count to a variable
, but once a symbol is popped from the stack, it is gone. Cannot simultaneously verify two independent counting constraints. - TM — persistent memory (tape): symbols written to the tape remain and can be re-read. Behaves like the von Neumann architecture (random-access, persistent memory). Can handle any computable language.
1.12 Countability and Undecidability (Spoilers)
An important meta-result motivates why undecidable problems exist:
- The set of all programs (over any fixed programming language) is countably infinite — programs can be listed lexicographically.
- The set of all problems (functions
, or equivalently subsets of ) is uncountably infinite (by Cantor’s diagonal argument).
Therefore, there are infinitely more problems than programs. Most problems — in a set-theoretic sense — have no algorithm. However, naturally occurring, well-structured problems are often decidable. The most famous undecidable problem is the Halting Problem: given a program
2. Definitions
- DFSA (Deterministic Finite State Automaton): A 5-tuple
with a total transition function ; each state-input pair leads to exactly one next state. - NFSA (Nondeterministic Finite State Automaton): A 5-tuple
with ; each state-input pair may lead to zero, one, or many next states. -NFSA: An NFSA whose transition function also allows -transitions: . -closure: For a state , is the set of all states reachable from via -transitions alone (including itself).- Extended transition function
: For an NFSA, is the inductive extension of to strings; and . - Acceptance (NFSA): A string
is accepted iff (existential nondeterminism). - Power set
: The set of all subsets of , including and itself. - Subset construction: Algorithm converting an NFSA to a DFSA by treating sets of NFSA states as individual DFSA states; yields
in the worst case. - Regular expression (RegExp): A formula built from
, , alphabet symbols, union ( ), concatenation ( ), and Kleene star ( ); denotes a regular language. - Kleene star (
): The set of all strings formed by concatenating zero or more strings from . - Thompson’s Construction: Algorithm converting a RegExp to an
-NFSA by structural induction on the RegExp. - Logicism: A philosophy of mathematics holding that mathematical truths are derivable from pure logical principles (Principia Mathematica).
- Gödel’s Incompleteness Theorem: In any sufficiently powerful consistent formal system, there exist true statements that are unprovable within the system (1931).
- Entscheidungsproblem: Hilbert’s 1928 question asking for an algorithm to decide whether any mathematical proposition is provable from given axioms.
- Church–Turing thesis: The conjecture that any effectively computable function is computable by a Turing Machine.
- Turing Machine (TM): A 7-tuple
consisting of states, input alphabet, memory alphabet, transition function, initial state, initial memory symbol, and accepting states; uses persistent read/write memory tapes. - Recursively enumerable language: A language recognized by some TM (the TM may loop on rejected inputs).
- Recursive (decidable) language: A language recognized by a TM that halts on all inputs; closed under complement.
- Halting Problem: The problem of deciding, given a program
and input , whether halts on ; proven undecidable by Turing. - Existential nondeterminism: Acceptance criterion requiring that at least one computation path accepts.
- Universal nondeterminism: Acceptance criterion requiring that all computation paths accept.
3. Formulas
- DFSA transition function:
- NFSA transition function:
-NFSA transition function:- Extended transition (NFSA, base):
- Extended transition (NFSA, step):
- NFSA acceptance:
- Subset construction — DFSA transition:
- Subset construction — accepting states:
- TM transition function (
tapes):
4. Practice
4.1. Build NFSAs for Three Languages (Lab 9, Task 1)
Build NFSAs that recognize the following languages:
Click to see the solution
(a)
Use the standard suffix-guessing pattern: the NFSA “guesses” the start of the final
: start state, self-loop on ; transition to on (guess: the final starts here). : transition to on . : transition to on . : accepting state (no outgoing transitions needed).
(b)
The language consists of a (possibly empty) block of
(accepting): self-loop on ; transition to on (enter the part where must be followed by ). : transition to (accepting) on . (accepting): transition to on (each new in must be followed by a ).
(c)
Three parallel suffix-detector branches, each two steps long:
: self-loop on ; transitions to on , to on , to on . : transition to (accepting) on (detected ). : transition to (accepting) on (detected ). : transition to (accepting) on (detected ). : single shared accepting state.
Answer: Three simple NFSA designs using the suffix-guessing pattern.
4.2. Convert NFSA to DFSA: Language Ending in 101 (Lab 9, Task 2)
The NFSA for
Apply the subset construction algorithm to produce the equivalent DFSA. Write out the full DFSA transition table and identify all accepting states.
Click to see the solution
NFSA transition table:
Subset construction:
Start:
| DFSA state | on |
on |
|---|---|---|
The DFSA has 4 states. The only accepting state is
Verification: Starting from
Answer: 4-state DFSA with accepting state
4.3. Convert NFSA to DFSA: Constrained Language over (Lab 9, Task 3)
The NFSA for
Apply subset construction to this NFSA and produce the equivalent DFSA.
Click to see the solution
NFSA transition table (accepting states:
Subset construction:
Start:
| DFSA state | on |
on |
|---|---|---|
Accepting DFSA states:
Answer: 5-state DFSA. The sink state
4.4. Convert NFSA to DFSA: Strings Ending in , , or (Lab 9, Task 4)
The NFSA for
Click to see the solution
NFSA (from Task 4.5(c)):
Subset construction (reachable states only):
Start:
| DFSA state | on |
on |
on |
|---|---|---|---|
Accepting DFSA states: those containing
Answer: 7-state DFSA. Accepting states are
4.5. Describe Languages of Regular Expressions (Lab 9, Task 5)
Over
Click to see the solution
: The empty language — no string is accepted, not even the empty string. : The language containing only the empty string . The Kleene star of the empty set allows zero repetitions of nothing, producing exactly . : All binary strings that contain the substring . The prefix matches any binary string (it generates ); then requires a block of three zeros; then allows any suffix. So the language is . : Strings in which every is immediately preceded by at least one (no leading without a preceding , except the optional leading single covered by the choice). More precisely: an optional leading , followed by zero or more blocks of the form (one or more zeros then a one), followed by zero or more trailing zeros. This is the set of binary strings in which never appears without a preceding , except possibly the very first character.
Answer: (1) empty language; (2)
4.6. Build Regular Expressions over (Lab 9, Task 6)
Construct regular expressions over
- The set of strings consisting of alternating
’s and ’s. - The set of strings containing an odd number of
’s. - The set of strings ending with
and not containing the substring . - The set of strings in which both the number of
’s and the number of ’s are even.
Click to see the solution
5. Alternating
Alternating strings start with either
Expanded: the string is either empty, or starts with an optional
6. Odd number of
Track parity of
This reads as: any number of
7. Strings ending with
Since
This generates all strings over
8. Even number of
We need to track parity of both
The regular expression is:
Interpretation: we build the string from blocks that preserve even parity on both counts. Each block is either
Answer: (5)
4.7. Construct NFSAs for Homework Languages (Lab 9, Task 7)
Construct NFSAs over
. Example strings: , , .
Click to see the solution
NFSA. We need to reject strings where a
(accepting, start): self-loop on ; transition to on . : transition to on (the required after the ); transition to (dead/rejecting) on (a immediately following another with no intervening ). (dead): self-loop on .
DFSA conversion. The NFSA is already nearly deterministic. The DFSA is identical;
NFSA. A linear chain spelling out
: self-loop on ; transition to on . . (accepting): self-loop on .
DFSA conversion. Apply subset construction. The resulting DFSA has up to
NFSA. The machine guesses when the second-to-last symbol starts:
: self-loop on ; transition to on ; transition to on . : transition to (accepting) on (last two were ). : transition to (accepting) on (last two were ). : accepting state (no outgoing transitions — the match is complete).
DFSA conversion. Apply subset construction starting from
| DFSA state | on |
on |
|---|---|---|
NFSA. Count zeros with states
for : self-loop on ; transition to on . (accepting): self-loop on ; transition to (dead) on . (dead): self-loop on .
DFSA conversion. This NFSA is already deterministic — the transition function is single-valued. The DFSA equals the NFSA directly (7 states:
Answer: NFSAs and DFSAs as described above for each of the four languages.
4.8. Prove Closure of NFSA Languages under Complement (Lecture 9, Task 1)
Is the class of languages recognized by NFSAs closed under complement? Provide a formal proof.
Click to see the solution
Claim: Yes, the class of languages recognized by NFSAs is closed under complement.
Proof.
Let
Step 1 — Convert NFSA to DFSA.
By the subset construction theorem, every NFSA is equivalent to some DFSA
Step 2 — Complement the DFSA.
Given a complete (total) DFSA
Step 3 — Verify correctness.
For any string
accepts iff . accepts iff , i.e., .
Therefore
Since
Conclusion. The class of NFSA-recognized languages (= regular languages) is closed under complement.
Why this argument does not work directly for NFSAs. The complement trick (swap
4.9. Verify Requires a Turing Machine (Lecture 9, Example 1)
Explain why the language
Click to see the solution
Why PDAs fail. A PDA can recognize
TM solution using one memory tape.
The TM uses the memory tape to store
- State
(initialization): Read the first and the initial symbol on the memory tape. Move: input stays, memory tape moves right ( ). Go to . - State
(counting ’s): Self-loop: for each read, write on the memory tape and advance both heads rightward ( ). When the input shows : stay on input, move memory head left ( ); go to . - State
(matching ’s): Self-loop: for each read, read (still present) on memory tape, advance input right but move memory left ( ). When input shows and memory shows : stay on input, move memory right ( ); go to . - State
(matching ’s): Self-loop: for each read, read on memory tape, advance both rightward. When input is blank and memory is blank: stay ( ); go to (accepting).
Key insight: The
Answer: A TM recognizes
4.10. Compare NFSA and DFSA for Strings Ending in 00 (Tutorial 9, Example 1)
Construct both an NFSA and a DFSA accepting all binary strings ending with
Click to see the solution
Key Concept: The DFSA must explicitly track all possible “suffixes in progress,” leading to more states. The NFSA can “guess” when the final
DFSA approach. The machine must remember the last two symbols seen:
: last symbol was (or start) — self-loop on ; go to on . : last symbol was — go back to on ; go to on . (accepting): last two symbols were — self-loop on ; go back to on .
NFSA approach. Much simpler — the machine “guesses” when the last
: self-loop on ; go to on (guess this is the start of the final ). : go to accepting on .
Answer: The NFSA uses the same number of states here but has far fewer transitions. For longer patterns the advantage becomes exponential.
4.11. Convert NFSA to DFSA via Subset Construction (Tutorial 9, Example 2)
Given the NFSA for strings ending in
NFSA transition table:
Click to see the solution
Step 1. Start with DFSA state
Step 2. Compute transitions from
- On
: → new DFSA state - On
: → DFSA state (already known)
Step 3. Compute transitions from
- On
: → new state - On
:
Step 4. Compute transitions from
- On
: - On
:
No new states. The DFSA transition table is:
Answer: The DFSA has 3 states, matching the DFSA from Example 4.1 (the states
4.12. Apply Thompson’s Construction to (Tutorial 9, Example 3)
Build an
Click to see the solution
Step 1 — Build
Step 2 — Build
Step 3 — Union
Step 4 — Kleene star
Step 5 — Simplify. After
- A single start/accepting state
(which also plays the role of ). (read a directly). (an intermediate state), then (read ). (loop for repetition, or equivalently is identified with after simplification).
Answer: The simplified NFSA accepts any concatenation of strings from